﻿using PC.AzureMultiApp.Core.Events;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Linq;
using PC.AzureMultiApp.Core.Models;
using System.Collections.Generic;
using PC.AzureMultiApp.Storage;

namespace Core.Test
{
    
    
    /// <summary>
    ///This is a test class for AzureEventTest and is intended
    ///to contain all AzureEventTest Unit Tests
    ///</summary>
    [TestClass()]
    public class AzureEventTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        [TestMethod()]
        [HostType("Moles")]
        public void ClearTest()
        {
            PC.AzureMultiApp.Storage.Moles.MEventDataSource.Constructor = (a) => { };

            bool called = false;
            PC.AzureMultiApp.Storage.Moles.MEventDataSource.AllInstances.Clear = (a)
            =>
            {
                called = true;
            };


            AzureEvent.Clear();
            Assert.IsTrue(called);
        }


        [TestMethod()]
        [HostType("Moles")]
        public void GetEvents_ZeroResults_Test()
        {
            PC.AzureMultiApp.Storage.Moles.MEventDataSource.Constructor = (a) => { };

            bool called = false;
            PC.AzureMultiApp.Storage.Moles.MEventDataSource.AllInstances.GetEvents = (a)
                =>
            {
                called = true;
                return new List<AzureEventEntity>();
            };

            IEnumerable<AzureEventModel> result = AzureEvent.GetEvents();
            Assert.IsTrue(result.Count() == 0);
            Assert.IsTrue(called);
        }

        [TestMethod()]
        [HostType("Moles")]
        public void GetEventsTest()
        {
            PC.AzureMultiApp.Storage.Moles.MEventDataSource.Constructor = (a) => { };

            bool called = false;
            PC.AzureMultiApp.Storage.Moles.MEventDataSource.AllInstances.GetEvents = (a)
                =>
            {
                called = true;
                return new List<AzureEventEntity>() 
                { 
                    new AzureEventEntity() {  EventTickCount = DateTime.Now.Ticks }, 
                    new AzureEventEntity() {  EventTickCount = DateTime.Now.Ticks},
                    new AzureEventEntity() {  EventTickCount = DateTime.Now.Ticks}
                };
            };

            IEnumerable<AzureEventModel> result = AzureEvent.GetEvents();
            Assert.IsTrue(result.Count() == 3);
            Assert.IsTrue(called);
        }

    }
}
